package com.example.finalframe.common;


public class ApiResult<T> {
    private int code;
    private String msg;
    //T是一个泛型，自定义
    private T data;

    public ApiResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ApiResult() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> ApiResult<T> success(String msg,T data){

        return new ApiResult(ApiConstant.API_SUCCESS,msg,data);
    }

    public static <T> ApiResult<T> success(T data){

        return success("操作成功", data);
    }

    public static <T> ApiResult<T> fail(int code, String msg){
        return new ApiResult<>(code, msg, null);
    }

    public static <T> ApiResult<T> fail(int code){
        return fail(code, "操作失败");
    }
}
